package com.pocketsweet.ui.uilib;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.pocketsweet.R;
import com.pocketsweet.service.UserService;

public class AvatarView extends FrameLayout {
	private ImageView ivImageView;
	private TextView tvCurrentAvatar;

	public AvatarView(Context context) {
		super(context);
		// 初始化
		init(context);
	}

	public AvatarView(Context context, AttributeSet attrs) {
		super(context, attrs);

		// 初始化
		init(context);
	}

	private void init(Context context) {
		View root = inflate(context, R.layout.view_avatar, null);
		ivImageView = (ImageView) root.findViewById(R.id.ivImageView);
		tvCurrentAvatar = (TextView) root.findViewById(R.id.tvCurrentAvatar);
		ivImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
		addView(root);
	}

	public void setAvatarText() {
		tvCurrentAvatar.setVisibility(View.VISIBLE);
	}
	public void setPhoto(String imageUrl) {
		UserService.displaySquare(imageUrl, ivImageView);
	}

	public void setImageResource() {
		ivImageView.setImageResource(R.drawable.btn_send_pic_selector);
//		UserService.displaySquare("drawable://" + R.drawable.btn_send_pic_selector, ivImageView);
	}
	
	public void setImageNull() {
//		UserService.displaySquare("drawable://" + R.drawable.icon_null, ivImageView);
		ivImageView.setImageResource(R.drawable.icon_null);
	}

}
